/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.siseventos.view.conversores;

import br.siseventos.dao.TipoLocalDao;
import br.siseventos.model.TdTipoLocal;
import br.siseventos.service.TipoLocalService;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

@FacesConverter("tipoLocalConversor")
public class ConversorTipoLocal extends BaseConverter {
    // <editor-fold desc="Campos">

    private TipoLocalService tipoLocalService = new TipoLocalService();
    // </editor-fold>
    // <editor-fold desc="Construtor">

    public ConversorTipoLocal() {
        tipoLocalService = new TipoLocalService();
    }
    // </editor-fold>
    // <editor-fold desc="Sobrescritas">

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        // Transformar string em objeto
        TdTipoLocal tipoLocal = null;
        try {
            if (value != null && "".compareTo(value) != 0) {
                tipoLocal = tipoLocalService.consultar(Integer.parseInt(value));
            }
        } catch (Exception ex) {
        }
        return tipoLocal;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        // Transformar objeto em string
        String r = null;
        try {
            if (value instanceof TdTipoLocal) {
                r = ((TdTipoLocal) value).getIdtTipoLocal().toString();
            }
        } catch (Exception e) {
        }

        return r;
    }
    // </editor-fold>
}
